package com.principle.factory.simplefactory.pizzastore.order;

import com.principle.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.principle.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.principle.factory.simplefactory.pizzastore.pizza.PepperPizza;
import com.principle.factory.simplefactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class OrderPizza {
   /* public OrderPizza(){
        Pizza pizza =null;
        String type;
        do {
            type=gettype();
            if (type.equals("greek")){
                pizza=new GreekPizza();
            }else if (type.equals("cheese")){
                pizza=new CheesePizza();
            }
            else if (type.equals("pepper")){
                pizza=new PepperPizza();
            } else{
                break;
            }
            pizza.prepare();;
            pizza.bake();
            pizza.cut();
            pizza.box();
        } while (true);
    }*/

    Pizza pizza=null;
    String orderType="";

    //构造器
    public  OrderPizza(){
        do {
        orderType=gettype();
        pizza = SimpleFactory.createPizza2(orderType);
        //输出 pizza
        if (pizza!=null){
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        }else {
            System.out.println("失败");
            break;
        }
    }while (true);
    }

    private String gettype(){
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type");
            String line = reader.readLine();
            return line;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
